﻿using System.Drawing;

namespace PlusPlusPaint.Layers.VisualObjects
{
    /// <summary>
    /// Represents a visual rectangle on the screen which is entirely of one
    /// colour rectangle will be equal to the dimensions of the containing
    /// layer.
    /// </summary>
    class FilledRectangle : DynamicallyGeneratedVisualObject
    {
        #region properties
        protected override string ObjectTypeName
        {
            get
            {
                return "FilledRectangle";
            }
        }
        #endregion

        #region constructors
        public FilledRectangle()
        {

        }

        public FilledRectangle(Point start, Point end)
        {
            SetBoxAround(start, end);
        }
        #endregion

        #region overrides
        public override bool PositionIsInHitbox(Point p)
        {
            return IsInRectangleBoundedBy(this.ClientRectangle, p);
        }

        public override IVisualObject Clone()
        {
            FilledRectangle copy = new FilledRectangle(Location, Location + Size);
            copy.Colour = this.Colour;
            return copy;
        }

        public override void BurnOn(Image im)
        {
            using (Brush br = new SolidBrush(this.Colour))
                Graphics.FromImage(im).FillRectangle(br, this.ClientRectangle);
        }
        #endregion

        #region static methods
        public static bool IsInRectangleBoundedBy(Rectangle r, Point p)
        {
            return
                p.X >= r.Left &&
                p.X <= r.Right &&
                p.Y >= r.Top &&
                p.Y <= r.Bottom;
        }
        #endregion
    }
}
